/*
 * utils.h
 *
 *  Created on: 2016-3-29
 *      Author: Administrator
 */

#ifndef UTILS_H_
#define UTILS_H_
#define IOException "java/io/IOException"
//MAX log message length
#define MAX_LOG_MESSAGE_LENGTH 256
//MAX data buffer size
#define MAX_BUFFER_SIZE 80
#define MAX_LINE 1024
#define  TAG    "jni"
#define   LOG_TAG    "LOG_TEST"
#define   LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
int port=9331;
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <android/log.h>
#include <unistd.h>
#include <net/if.h>
#include <arpa/inet.h>
#include<string.h>
#include <netdb.h>
#include "android/log.h"
#include <stdlib.h>
#include <sys/socket.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include<unistd.h>
#include<stdio.h>

static void ThrowException(JNIEnv* env,const char* message);
static int get_ip_from_host(char *ipbuf, const char *host, int maxlen);

static void ThrowException(JNIEnv* env,const char* message) {
	jclass clazz = env->FindClass(IOException);
	if (clazz != NULL) {
		env->ThrowNew(clazz, message);
		env->DeleteLocalRef(clazz);
	}
}
static int get_ip_from_host(char *ipbuf, const char *host, int maxlen)
{
	struct sockaddr_in sa;
	sa.sin_family = AF_INET;
	if (inet_aton(host, &sa.sin_addr) == 0)
	{
		struct hostent *he;
		he = gethostbyname(host);
		if (he == NULL)
			return -1;
		memcpy(&sa.sin_addr, he->h_addr, sizeof(struct in_addr));
	}
	strncpy(ipbuf, inet_ntoa(sa.sin_addr), maxlen);
	return 0;
}



#endif /* UTILS_H_ */


